//
//  ActivityViewController.m
//  PetAPP
//
//  Created by dllo on 16/1/29.
//  Copyright © 2016年 Yuming. All rights reserved.
//

#import "ActivityViewController.h"
#import "NetworkingHandle.h"
#import "ModelOfActivity.h"
#import "CellOfActivity.h"
#import "ActivityOfViewController.h"




@interface ActivityViewController () <UITableViewDataSource, UITableViewDelegate, CellOfActivityDelegate>

@property (nonatomic, retain) UITableView *tableView;

@property (nonatomic, retain) NSMutableArray *dataArr;

@end

@implementation ActivityViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.dk_backgroundColorPicker = DKColorWithColors([UIColor whiteColor], [UIColor colorWithRed:0.2952 green:0.2952 blue:0.2952 alpha:1.0]);
    self.title = @"活动";
    
    [self handleData];
    [self createTableView];
    
}

- (void)dealloc {
    _tableView.delegate = nil;
    [_tableView release];
    [_dataArr release];
    [_URLDic release];
    [super dealloc];


}

- (void)backButtonPopView {
    [self.navigationController popViewControllerAnimated:YES];

}

#pragma mark - 通过代理实现传值并推出新页面
- (void)pushNewVCWithModel:(ModelOfActivity *)model {
//    ActivityOfViewController *activityVC = [[ActivityOfViewController alloc] init];
//    
//    
//    [self presentViewController:activityVC animated:YES completion:nil];
//    [activityVC release];
    
    NSLog(@"ddd");

}

- (void)handleData {
    [NetworkingHandle handleWorkData:[self.URLDic objectForKey:@"url"] AndBody:[self.URLDic objectForKey:@"body"] value:[self.URLDic objectForKey:@"value"] handleBlock:^(id result) {
       
        self.dataArr = [NSMutableArray array];
        NSArray *tempArr = [result objectForKey:@"response"];
        for (NSDictionary *dic in tempArr) {
            ModelOfActivity *model = [[ModelOfActivity alloc] init];
            [model setValuesForKeysWithDictionary:dic];
            [self.dataArr addObject:model];
            [model release];
        }
        [self.tableView reloadData];
    }];
}

#pragma mark - 模拟实现间隔
//section底部视图
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    UIView *view=[[[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 1)] autorelease];
    view.backgroundColor = [UIColor clearColor];
    
    return view;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    
    if (section == self.dataArr.count - 1) {
        return 0;
    }else{
    
        return 10;
    }
}

#pragma mark - 设置cell样式
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    CellOfActivity *cell = [tableView dequeueReusableCellWithIdentifier:@"poolOfCell"];
    
    ModelOfActivity *model = [self.dataArr objectAtIndex:indexPath.section];
    
    [cell passPicAndTitleWithModel:model];
    
    cell.delegate = self;
    
    return cell;
    

}
#pragma mark - 设置多个分区
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {


    return self.dataArr.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {


    return 1;
}


- (void)createTableView {

    self.tableView = [[UITableView alloc] initWithFrame:[UIScreen mainScreen].bounds style:UITableViewStylePlain];
    [self.view addSubview:_tableView];
    [_tableView release];
    
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    
    [self.tableView registerClass:[CellOfActivity class] forCellReuseIdentifier:@"poolOfCell"];
    
    self.tableView.rowHeight = 200;
    self.tableView.dk_backgroundColorPicker = DKColorWithColors([UIColor colorWithRed:0.9625 green:0.9625 blue:0.9625 alpha:1.0], [UIColor colorWithRed:0.2952 green:0.2952 blue:0.2952 alpha:1.0]);
    
    
    
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
